﻿using System;
using System.Diagnostics.Contracts;

namespace OpenWaves.ImageTransformations
{
    [ContractClass(typeof(ImageContract))]
    public interface IImage
    {
        int Width { get; }
        int Height { get; }

        void Scale(int width, int height);
        void Crop(int left, int top, int width, int height);
    }

    [ContractClassFor(typeof(IImage))]
    abstract class ImageContract : IImage
    {
        public int Width
        {
            get { throw new NotImplementedException(); }
        }

        public int Height
        {
            get { throw new NotImplementedException(); }
        }

        public void Scale(int newWidth, int newHeight)
        {
            Contract.Requires<ArgumentOutOfRangeException>(newWidth >= 0);
            Contract.Requires<ArgumentOutOfRangeException>(newHeight >= 0);

            throw new NotImplementedException();
        }

        public void Crop(int left, int top, int newWidth, int newHeight)
        {
            Contract.Requires<ArgumentOutOfRangeException>(left >=0 && left < this.Width);
            Contract.Requires<ArgumentOutOfRangeException>(top >=0 && top < this.Height);
            Contract.Requires<ArgumentOutOfRangeException>(left + newWidth <= this.Width);
            Contract.Requires<ArgumentOutOfRangeException>(top + newHeight <= this.Height);

            throw new NotImplementedException();
        }

        [ContractInvariantMethod]
        private void Invariants()
        {
            Contract.Invariant(this.Width >= 0);
            Contract.Invariant(this.Height >= 0);
        }
    }
}